﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Skybound.Gecko;
using System.Xml;
using System.IO;
using WeifenLuo.WinFormsUI.Docking;

namespace NasuTek.Shion
{
    public partial class Debugger : DockContent
    {

        public Debugger(Form1 form)
        {
            InitializeComponent();
        }

        private void Debugger_Load(object sender, EventArgs e)
        {
            propertyGrid1.SelectedObject = Form1.em;
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            ReFresh();
        }

        public void ReFresh()
        {   
            //HTML Inspector
            if (Program.debug == true) { htmlInspector1.HtmlBody = File.ReadAllText(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "ShionTemp-Debug\\ShionTempHTML.html")); }
            else { htmlInspector1.HtmlBody = File.ReadAllText(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "ShionTemp\\ShionTempHTML.html")); }
            htmlInspector1.Parse();

            // Get Dictionaries
            treeView2.Nodes.Clear();
            TreeNode Text = new TreeNode("ChannelText");
            foreach (KeyValuePair<string, Dictionary<string, string[]>> i in Form1.ChannelText)
            {
                TreeNode TextLevel2 = new TreeNode(i.Key);
                foreach (KeyValuePair<string, string[]> x in i.Value)
                {
                    TreeNode TextLevel3 = new TreeNode(x.Key);
                    foreach (string y in x.Value)
                    {
                        TextLevel3.Nodes.Add(y);
                    }
                    TextLevel2.Nodes.Add(TextLevel3);
                }
                Text.Nodes.Add(TextLevel2);
            }
            treeView2.Nodes.Add(Text);

            TreeNode NickLists = new TreeNode("NamesList");
            foreach (KeyValuePair<string, Dictionary<string, string[]>> i in Form1.NamesList)
            {
                TreeNode NickListsLevel2 = new TreeNode(i.Key);
                foreach (KeyValuePair<string, string[]> x in i.Value)
                {
                    TreeNode NickListsLevel3 = new TreeNode(x.Key);
                    foreach (string y in x.Value)
                    {
                        NickListsLevel3.Nodes.Add(y);
                    }
                    NickListsLevel2.Nodes.Add(NickListsLevel3);
                }
                NickLists.Nodes.Add(NickListsLevel2);
            }
            treeView2.Nodes.Add(NickLists);

            TreeNode OpsLists = new TreeNode("Ops");
            foreach (KeyValuePair<string, Dictionary<string, List<string>>> i in Form1.Ops)
            {
                TreeNode OpsListsLevel2 = new TreeNode(i.Key);
                foreach (KeyValuePair<string, List<string>> x in i.Value)
                {
                    TreeNode OpsListsLevel3 = new TreeNode(x.Key);
                    foreach (string y in x.Value)
                    {
                        OpsListsLevel3.Nodes.Add(y);
                    }
                    OpsListsLevel2.Nodes.Add(OpsListsLevel3);
                }
                OpsLists.Nodes.Add(OpsListsLevel2);
            }
            treeView2.Nodes.Add(OpsLists);

            TreeNode VopsLists = new TreeNode("Vops");
            foreach (KeyValuePair<string, Dictionary<string, List<string>>> i in Form1.Vops)
            {
                TreeNode VopsListsLevel2 = new TreeNode(i.Key);
                foreach (KeyValuePair<string, List<string>> x in i.Value)
                {
                    TreeNode VopsListsLevel3 = new TreeNode(x.Key);
                    foreach (string y in x.Value)
                    {
                        VopsListsLevel3.Nodes.Add(y);
                    }
                    VopsListsLevel2.Nodes.Add(VopsListsLevel3);
                }
                VopsLists.Nodes.Add(VopsListsLevel2);
            }
            treeView2.Nodes.Add(VopsLists);

            TreeNode HopsLists = new TreeNode("HalfOps");
            foreach (KeyValuePair<string, Dictionary<string, List<string>>> i in Form1.HalfOps)
            {
                TreeNode HopsListsLevel2 = new TreeNode(i.Key);
                foreach (KeyValuePair<string, List<string>> x in i.Value)
                {
                    TreeNode HopsListsLevel3 = new TreeNode(x.Key);
                    foreach (string y in x.Value)
                    {
                        HopsListsLevel3.Nodes.Add(y);
                    }
                    HopsListsLevel2.Nodes.Add(HopsListsLevel3);
                }
                HopsLists.Nodes.Add(HopsListsLevel2);
            }
            treeView2.Nodes.Add(HopsLists);

            TreeNode Hostmasks = new TreeNode("Hostmasks");
            foreach (KeyValuePair<string, List<string>> i in Form1.em.HostMasks)
            {
                TreeNode HostmasksLevel2 = new TreeNode(i.Key);
                foreach (string y in i.Value)
                {
                    HostmasksLevel2.Nodes.Add(y);
                }
                Hostmasks.Nodes.Add(HostmasksLevel2);
            }
            treeView2.Nodes.Add(Hostmasks);
        }
    }
}
